<template>
    <div>
        <div class="header">
            <div class="logo"><img src="../../images/home/logo.png"></div>
            <div class="info">
                <ul>
                    <li v-if="items.url"><img :src="items.url"><span>{{items.username}}</span></li>
                    <li v-else><img src="../../images/home/head-img.jpg"><span>{{items.username}}</span></li>
                    <li @click="loginOut()">退出</li>
                </ul>
            </div>
        </div>
        <div class="menu" v-if="navBar&&todo.isMenu==1">
            <div class="my-slider">
                <span class="left" @click="leftAnimate()" v-if="navBar.length>3"><i
                        class="iconfont icon-zuo"></i></span>
                <span class="right" @click="rightAnimate()" v-if="navBar.length>3"><i
                        class="iconfont icon-you"></i></span>
                <ul>
                    <li v-for="(item, index) in navBar" :class="{active:navId==item.id}">
                        <a :href="item.content1+'?pId='+pId+'&navId='+item.id" v-if="item.content3!='blank'">{{item.name}}</a>
                        <a :href="item.content1+'JSSOSESSIONID='+JSSOSESSIONID" v-if="item.content3=='blank'">{{item.name}}</a>
                    </li>
                </ul>
            </div>
        </div>
        <div class="container" v-if="todo.isMenu==0">
            <div class="banner">
                <img src="../../images/home/banner.jpg">
                <div class="search">
                    <h1>FERN外汇欢迎您</h1>
                    <div class="con">
                        <input type="text" autocomplete="off" placeholder="请输入关键词"><span>搜索</span>
                    </div>
                </div>
            </div>
            <div class="nav">
                <ul>
                    <li v-for="(item, index) in menu" :class="['nav-'+(index-4)]" v-if="index>4">
                        <a :href="item.content1+'JSSOSESSIONID='+JSSOSESSIONID" v-if="item.content3=='blank'"
                           target="_blank">
                            <span>{{ item.name }}</span>
                            <p v-if="index===7">全方位了解市场活动，积极进行有效推广</p>
                            <p v-if="index===9">轻松监控财务状况，安全快捷</p>
                        </a>
                        <a :href="item.content1+'?pId='+item.id+'&navId='+item.content3" v-else>
                            <span>{{ item.name }}</span>
                            <p v-if="index===7">全方位了解市场活动，积极进行有效推广</p>
                            <p v-if="index===9">轻松监控财务状况，安全快捷</p>
                        </a>
                    </li>
                </ul>
            </div>
            <div class="suggest">
                <h1>客服QQ3435444903</h1>
                <h2>我们的进步，源自每一次您与我们的交流</h2>
                <div class="submit">
                    <textarea placeholder="请填写您宝贵的意见"></textarea>
                    <div class="btn">
                        <i class="iconfont icon-send"></i><span>提交</span>
                    </div>
                </div>
            </div>
        </div>
        <div class="footer">
            <ul>
                <li v-for="(item,index) in menu" v-if="index<4">
                    <a :href="item.content1" v-if="item.content3=='blank'" target="_blank"><i
                            class="iconfont"></i><span>{{item.name}}</span></a>
                    <a :href="item.content1" v-else><i class="iconfont"></i><span>{{item.name}}</span></a>
                </li>
            </ul>
        </div>
    </div>
</template>
<script>
    import AjaxHttp from '../../js/ajaxHttp.js';
    import Tools from '../../js/tools.js';
    import Config from '../../js/config.js';
    export default{
        props: ['todo'],
        data: function () {
            return {
                items: '',
                menu: '',
                navBar: '',
                pId: '',
                navId: '',
                indexAnimate: 0,
                JSSOSESSIONID: ''
            }
        },
        created: function () {
            console.log(this);
            this.indexAnimate = this._props.todo.indexAnimate;
            this.JSSOSESSIONID = Config.JSSOSESSIONID;
            //console.log(AjaxHttp);
            var _this = this, thisId, navBarArray = [], indexMenu = [], key = Tools.getUrlKey('pId');
            this.navId = Tools.getUrlKey('navId');
            this.pId = Tools.getUrlKey('pId');
            AjaxHttp.getHttp('fxsys/menu/getMenuList').then(function (data) {
                data.url = Config.domain + data.url;
                console.log(data.url);
                _this.items = data;
                for (var i = 0; i < data.menus.length; i++) {
                    data.menus[i].content1 = Config.isProduct ? data.menus[i].content1.replace(/public/, "/cloudfx/public") : data.menus[i].content1.replace(/public/, "");
                    if (data.menus[i].name == 'menu') {
                        thisId = data.menus[i].id;
                    }
                    if (key) {
                        if (key == data.menus[i].parentId) {
                            navBarArray.push(data.menus[i]);
                        }
                    }
                }
                for (var j = 0; j < data.menus.length; j++) {
                    if (thisId == data.menus[j].parentId) {
                        indexMenu.push(data.menus[j]);
                    }
                }
                indexMenu.sort(function (a, b) {
                    return a.sort - b.sort
                });
                navBarArray.sort(function (a, b) {
                    return a.sort - b.sort
                });
                //console.log(indexMenu);
                //console.log(navBarArray);
                _this.menu = indexMenu;
                _this.navBar = navBarArray;
                if (_this._props.todo.isMenu == 1) {
                    setTimeout(function () {
                        var lenWidth = document.querySelector('.my-slider ul li').clientWidth;
                        document.querySelector('.menu ul').style.left = -lenWidth * _this.indexAnimate + 'px';
                    }, 500);
                }
            });
        },
        methods: {
            leftAnimate: function () {
                var lenWidth = document.querySelector('.my-slider ul li').clientWidth, len = document.querySelectorAll('.my-slider ul li').length;
                this.indexAnimate -= 1;
                if (this.indexAnimate <0) {
                    this.indexAnimate = len - 3;
                }
                document.querySelector('.menu ul').style.left = -lenWidth * this.indexAnimate + 'px';
            },
            rightAnimate: function () {
                var len = document.querySelectorAll('.my-slider ul li').length - 3, lenWidth = document.querySelector('.my-slider ul li').clientWidth;
                if (this.indexAnimate < len) {
                    this.indexAnimate += 1;
                    document.querySelector('.menu ul').style.left = -lenWidth * this.indexAnimate + 'px';
                } else {
                    this.indexAnimate = 0;
                    document.querySelector('.menu ul').style.left = -lenWidth * this.indexAnimate + 'px';
                }
            }
        }
    }
</script>